package com.example.service.Impl;

import com.example.mapper.UserMapper;
import com.example.pojo.User;
import com.example.service.UserService;
import com.example.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper usermapper;
    @Override
    public User findbyusername(String username) {
        User u=usermapper.findbyusername(username);
        return u;
    }

    @Override
    public void register(String username, String password) {
        usermapper.add(username,password);

    }
    @Override
    public void update(User user){
        user.setUpdateTime(LocalDateTime.now());
        usermapper.update(user);
    }
    @Override
    public void updateAvatar(String avatarUrl){
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        usermapper.updateAvatar(avatarUrl,id);
    }

    @Override
    public void updatePwd(String newPwd) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        usermapper.updatepwd(newPwd,id);
    }
}

